<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>推说 - 简单看发微博</title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
    <link rel="stylesheet" href="/styles/screen.css" type="text/css" media="screen, projection"> 
    <style type="text/css">
        a {text-decoration:none;}
        .bound-sites { padding:10px;}
        .bound-sites li {list-style:none;}
    </style>
</head>
<body>
<div class="container">

<div class="prepend-4"><h1><div style="float:left;width:48px;height:48px;border:1px solid #58C5FD;border-radius:5px;"><img src="/images/ts_48.png"></div>推说</h1></div>
<hr>

<div class="span-4">&nbsp;</div>

<div class="span-14">
    <div class="">
    <a href="javascript:void(0)" onclick="bind('weibo.com')">绑定新浪微博</a>&nbsp;
    <!--
    <a href="javascript:void(0)" onclick="bind('t.qq.com')">腾讯微博</a>&nbsp;
    <select id="">
        <option>选择其他</option>
        <option value="">网易微博</option>
        <option value="">搜狐微博</option>
        <option value="">豆瓣说</option>
        <option value="">人人网</option>
        <option value="">开心网</option>
    </select>
    -->
    </div>

    <div id="msg"></div>

    <div class="bound-sites">
    <ul id="sites">
        <li></li>
    </ul>

    </div>
</div>


<div class="span-6 last">
<p>
推说官方网站：<br /><a href="http://tuihe.com/tuishuo/" target="_blank">tuihe.com/tuishuo/</a>
</p>
<p>关注<span style="color:#58C5FD;font-weight:bold;">推说</span>官方微博<br /><a href="http://weibo.com/tuishuo/" target="_blank">weibo.com/tuishuo/</a></p>
</div>


<hr />
<div class="prepend-4">
@2011&nbsp;&nbsp;&nbsp;tuihe.com
</div>
</div>
<script type="text/javascript">
function bind(site) {
    var oauthConfig = (localStorage["oauthConfig"] == null) ? null : JSON.parse(localStorage["oauthConfig"]);
/*
    if (oauthConfig == null) {
        var bgPage = chrome.extension.getBackgroundPage();
        bgPage.initConfig();
        oauthConfig = JSON.parse(localStorage["oauthConfig"]);
    }
*/

    var sites = (localStorage['boundSites'] == null) ? null : JSON.parse(localStorage['boundSites']);
    if (sites != null && sites[site] != null) {
        return;
    }

    $.each(oauthConfig, function(k, v) {
        if (v.site == site) {
            chrome.extension.sendRequest({ "action": "oauth", "site": site, "data": v }, function(response) {
                bindList();
                $("#msg").hide();
            });
        }
    });
}

function bindList () {
    var sites = (localStorage['boundSites'] == null) ? null : JSON.parse(localStorage['boundSites']);
    if (sites != null) {
        $.each(sites, function(k,v) {
            var html = [];
            html.push("<li><a href='http://weibo.com/");
            html.push(v.originalUser.id);
            html.push("/' target='_blank'><img src='");
            html.push(v.originalUser.profile_image_url);
            html.push("' alt='' title='");
            html.push(v.originalUser.screen_name);
            html.push("' /></a>");
            html.push("<br /><a href='javascript:cancelBind(\"");
            html.push(k);
            html.push("\");'>取消绑定</a>");
            //html.push(v.originalUser.name);
            html.push("</li>");
            $('#sites').append(html.join(''));
        });
    }
}

function cancelBind (site) {
    localStorage.removeItem("boundSites");
    localStorage.removeItem("oauth_token" + site);
    localStorage.removeItem("oauth_token_secret" + site);

    location.reload(true);
    //$("#msg").addClass('success').html("取消绑定成功。");
    //bindList();
}

(function() {
    if (localStorage['boundSites'] == null) {
        $("#msg").addClass('notice').text("你还没有绑定新浪微博！");
    }
    bindList();
})();
</script>
</body>
</html>
